﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraEditors;
using DevExpress.XtraBars;
using Event;
using DevExpress.XtraBars.Docking;

namespace DebugVersion
{
    public partial class Version : UserControl
    {
        public Version()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 版本切换
        /// </summary>
        public event Event.EventGlobal.DeVersion EvVersion;


        private RequestParameteData rpd;

        /// <summary>
        /// 当前node
        /// </summary>
        private TreeListNode currentNode;

        private DockPanel dp;

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="_rpd"></param>
        /// <param name="_tln"></param>
        /// <param name="dp"></param>
        public void BuildDebugVersion(RequestParameteData _rpd, TreeListNode _tln, DockPanel _dp)
        {
            this.rpd = _rpd;
            this.currentNode = _tln;
            this.dp = _dp;
            this.textEdit_名称填写.EditValue = (string)this.currentNode.GetValue("key");
        }

        /// <summary>
        /// 版本切换
        /// </summary>
        /// <param name="_rpd"></param>
        /// <param name="_tln"></param>
        public void BuildDebugLoadVersion(RequestParameteData _rpd, TreeListNode _tln)
        {
            this.rpd = _rpd;
            this.currentNode = _tln;
        }

        /// <summary>
        /// 改变指定的node名称
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textEdit_名称填写_EditValueChanged(object sender, EventArgs e)
        {
            TextEdit te = (TextEdit)sender;
            this.dp.Text = te.Text;
            this.currentNode.SetValue("key", te.Text);
        }


        private void barManager_版本选择_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.Item is BarCheckItem)
            {
                CheckedChanged((BarCheckItem)e.Item);
            }
        }

        private void CheckedChanged(BarCheckItem bci)
        {
            this.barCheckItem_版本1.Checked = false;
            this.barCheckItem_版本2.Checked = false;
            this.barCheckItem_版本3.Checked = false;
            if (bci.Name.Contains("版本1"))
            {
                rpd.requestVersion = 1;
                if (EvVersion != null)
                {
                    EvVersion(1);
                }
                this.dropDownButton_版本管理切换.Text = "版本1";
            }
            if (bci.Name.Contains("版本2"))
            {
                rpd.requestVersion = 2;
                if (EvVersion != null)
                {
                    EvVersion(2);
                }
                this.dropDownButton_版本管理切换.Text = "版本2";
            }
            if (bci.Name.Contains("版本3"))
            {
                rpd.requestVersion = 3;
                if (EvVersion != null)
                {
                    EvVersion(3);
                }
                this.dropDownButton_版本管理切换.Text = "版本3";
            }
            bci.Checked = true;


        }
    }
}
